<!DOCTYPE html>
<html>

	<head lang="en">
		<meta charset="UTF-8">
		<title>登录</title>
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<meta name="format-detection" content="telephone=no">
		<meta name="renderer" content="webkit">
		<meta http-equiv="Cache-Control" content="no-siteapp" />

		<link rel="stylesheet" href="static/css/amazeui.css" />
		<link href="static/css/dlstyle.css" rel="stylesheet" type="text/css">
		<link rel="stylesheet" href="static/css/bootstrap.min.css" />	
	</head>

	<body>

		<div class="login-boxtitle" style="height: 100px;">
			<div class="logoBig">
				<img src="static/images/logo.png" style="margin-left: 0px ; height: 100px;">
			</div>
		</div>

		<div class="login-banner" id="container">
			<div class="login-main" >
				<div class="login-banner-bg"><span></span><img src="static/images/big.jpg" /></div>
				<div class="login-box" style="margin-top: 20px;">

					<h3 class="title">登录商城</h3>

					<div class="clear"></div>

					<div class="login-form"  style="background: none; margin-top: 15px;">
						<form>
							<div class="user-name"  style="margin-top: 20px;">
								<label for="user"><span class="glyphicon glyphicon-user" aria-hidden="true"></span></label>
								<input type="text" name="" id="userName" v-model="username" @keyup="checkInfo" placeholder="邮箱/手机/用户名">
							</div>
							<div class="user-pass"  style="margin-top: 20px;">
								<label for="password"><span class="glyphicon glyphicon-lock" aria-hidden="true"></span></label>
								<input type="password" name="" id="userPwd" v-model="password" @keyup="checkInfo" placeholder="请输入密码">
							</div>
						</form>
					</div>

					<div class="login-links" >
						<label for="remember-me"><input id="remember-me" type="checkbox">记住密码</label>
						<a href="#" class="am-fr">忘记密码</a>
						<br />
					</div>
					<div class="am-cf">
						<input type="submit" name="" value="登 录" @click="doSubmit" id="loginSubmit" class="am-btn am-btn-primary am-btn-sm">
					</div>
					<div class="am-cf">
						<input type="button" onclick="javascript:window.location.href='register.html'" value="注 册" class="am-btn am-btn-default am-btn-sm">
					</div>
					<div class="partner">
						<h4 id="tips" :style="colorStyle">{{tips}}</h4>
					</div>

				</div>
			</div>
		</div>

		<div class="footer ">
			<div class="footer-hd ">

			</div>
			<div class="footer-bd ">
				<p>
					<a href="# ">联系我们</a>
					<a href="# ">网站地图</a>
				</p>
			</div>
		</div>
		
		<script type="text/javascript" src="static/js/jquery-1.9.min.js"></script>
		<script src="static/js/cookie_util.js"></script>
		<script type="text/javascript" src="static/js/v2.6.10/vue.js"></script>
		<script type="text/javascript" src="static/js/v2.6.10/axios.min.js"></script>
		<script type="text/javascript">
			// 因为服务器的路径名，因部署不同可能不一样，定义在这里方便修改
			var baseUrl="http://localhost:8080/";
			var vm = new Vue({
				el:"#container",
				data:{
					username:"",
					password:"",
					tips:"",
					colorStyle:"color:red",
					isRight:false
				},
				methods:{
					doSubmit:function(){
						if(vm.isRight){
							var url=baseUrl+"user/login"
							//通过swagger接口说明文档，知道后端的登录请求发送的是get请求，接收的参数分别是username、password
							axios.get(url,{
								params:{
									username:vm.username,
									password:vm.password
								}
							})
							.then((res)=>{
								// res.data才表示接口返回的数据
								var vo=res.data;
								console.log(vo);
								if(vo.code==1){//通过后端知道1代表成功，0代表失败
									//如果登录成功，就把token存储到cookie
									setCookieValue("token",vo.msg);
									//将用户名称和头像的路径保存在cookie
									setCookieValue("username",vo.data.username);
									setCookieValue("userimg",vo.data.userImg);
									window.location.href="index.html"
								}else{
									vm.tips="登录失败，账号或密码错误!!";
								}
							});
							
							
						}else{
							vm.tips="请输入正确的账号名和密码！！";
						}
					},
					checkInfo(){
						if(vm.username==""){
							vm.tips="请输入账号或用户名！！";
							vm.isRight=false;
						}else if(vm.username.length<3||vm.username.length>20){
							vm.tips="账号长度必须为3-20个字符！！";
							vm.isRight=fasle;
						}else{
							//账号合法，校验密码
							if(vm.password==""){
								vm.tips="请输入密码！！";
								vm.isRight=false;
							}else if(vm.password.length<4||vm.password.length>16){
								vm.tips="密码长度必须为4-16个字符！！";
								vm.isRight=fasle;
							}else{
								vm.tips="";
								vm.isRight=true;
							}
						}
					}
				}
			});
			
		</script>
	</body>

</html>